﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoDbObject;
using SZJT.Utility.DataSource;

namespace Colligate.DataSource.DriverTraining.Business.Vehicle
{
    class BusinessVehicleInfo : BaseLegoModule
    {
        private const string TABLE_VEHICLE_INFO = "BusinessVehicleInfo";

        public BusinessVehicleInfo(IDataSourceLayer dataLayer)
            : base(new string[] { TABLE_VEHICLE_INFO }, dataLayer)
        {
        }

        #region 返回Lego模块涉及到的数据名称的结构信息
        /// <summary>
        /// 返回Lego模块涉及到的数据名称的结构信息
        /// </summary>
        /// <param name="strDataName">基础表名称</param>
        /// <returns>表结构信息</returns>
        override public IFieldInfo[] GetStructInfo(string strDataName)
        {
            // 建立IFieldInfo列表
            // CFieldInfo(字段名, 类型, 长度, 索引, 状态, 字段说明, 字段帮助, 显示的格式化字符串, 字段宽度, 关联记录)
            // 类型： text，byte，short，long，single，double，currency，date，logical，memo，binary
            // 索引： 0 无索引，1 重复索引，2 唯一索引，3 关键字段
            // 状态： 0 系统字段，>1显示信息的字段， 2 用于标识记录名称的字段

            IFieldInfo[] tableStructInfo;
            switch (strDataName)
            {
                case TABLE_VEHICLE_INFO:	 // 驾校车辆基本信息
                    tableStructInfo = new IFieldInfo[7];
                    tableStructInfo[0] = new CFieldInfo("fVehicleGuid", "text", 36, 2, 0, "驾校车辆基本信息", "驾校车辆基本信息", "", 52, 0);
                    tableStructInfo[1] = new CFieldInfo("fSchoolGuid", "text", 36, 0, 1, "单位标识", "单位标识", "", 52, 0);
                    tableStructInfo[2] = new CFieldInfo("fSchoolName", "text", 50, 0, 1, "单位名称", "单位名称", "", 52, 0);
                    tableStructInfo[3] = new CFieldInfo("fVehicleLicense", "text", 10, 0, 1, "车牌号", "车牌号", "", 52, 0);
                    tableStructInfo[4] = new CFieldInfo("fVehicleUnit", "text", 20, 0, 1, "车辆型号", "车辆型号", "", 52, 0);
                    tableStructInfo[5] = new CFieldInfo("fVehicleStatus", "text", 10, 0, 1, "车辆状态[可用|报废|停用]", "车辆状态[可用|报废|停用]", "", 52, 0);
                    tableStructInfo[6] = new CFieldInfo("fVehiclePhone", "text", 15, 0, 1, "车载电话号码", "车载电话号码", "", 52, 0);
                    break;


                default: tableStructInfo = null; break;
            }
            return tableStructInfo;
        }
        #endregion

        
        public IDBDataObject GetVehicleInfoData(string strDataGuid)
        {
            string tableName = GetStructGlobalName(TABLE_VEHICLE_INFO);
            return DataLayer.GetDBDataObject(tableName, string.Format("fVehicleGuid = '{0}'", strDataGuid));
        }

        public IDBBigObjectSet GetVehileList(string vehicleLicense, string vehicleUnit, string vehicleStatus, string vehiclePhone)
        {
            QueryFilter queryFilter = new QueryFilter();

            queryFilter.AddFilter("fVehicleLicense", vehicleLicense, "{0} like '%{1}%'");
            queryFilter.AddFilter("fVehicleUnit", QueryFilter.FilterType.TEXT, vehicleUnit, true);
            queryFilter.AddFilter("fVehicleStatus", QueryFilter.FilterType.TEXT, vehicleStatus, true);
            queryFilter.AddFilter("fVehiclePhone", QueryFilter.FilterType.TEXT, vehiclePhone, true);

            return DataLayer.GetDBBigObjectSet(GetStructGlobalName(TABLE_VEHICLE_INFO), queryFilter.FilterString, "fVehicleLicense");
        }

    }
}
